package com.wen.common;

import com.wen.common.constant.MsgCode;
import com.wen.common.constant.MsgCodeEnum;

/**
 * ResultDto工厂对象.
 */
public final class ResultDtoFactory {

    public static ResultDto success() {
        ResultDto resultDto = new ResultDto();
        resultDto.setMessage(MsgCodeEnum.SUCCESS.getMessage());
        resultDto.setCode(MsgCodeEnum.SUCCESS.getCode());

        return resultDto;
    }

    /**
     * 根据指定的消息，构建成功返回对象
     *
     * @return
     */
    public static ResultDto success(String message) {
        ResultDto resultDto = new ResultDto();
        resultDto.setCode(MsgCodeEnum.SUCCESS.getCode());
        resultDto.setMessage(message);

        return resultDto;
    }

    public static <T> ResultDto success(T data) {
        ResultDto resultDto = new ResultDto();
        resultDto.setCode(MsgCodeEnum.SUCCESS.getCode());
        resultDto.setMessage(MsgCodeEnum.SUCCESS.getMessage());
        resultDto.setData(data);

        return resultDto;
    }

    public static ResultDto ERROR() {
        ResultDto resultDto = new ResultDto();
        resultDto.setCode(MsgCodeEnum.ERROR.getCode());
        resultDto.setMessage(MsgCodeEnum.ERROR.getMessage());

        return resultDto;
    }

    public static ResultDto ERROR(String message) {
        ResultDto resultDto = new ResultDto();
        resultDto.setCode(MsgCodeEnum.ERROR.getCode());
        resultDto.setMessage(message);

        return resultDto;
    }

    public static ResultDto ERROR(MsgCode msgCode) {
        ResultDto resultDto = new ResultDto();
        resultDto.setCode(msgCode.getCode());
        resultDto.setMessage(msgCode.getMessage());

        return resultDto;
    }
}
